﻿using SmartRS.com.vn.smartrs.domain;
using SmartRS.com.vn.smartrs.util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SmartRS.com.vn.smartrs.controller
{
    public class FoodKindController
    {
        //filter food by key search
        public static IList<FoodKind> filterFoodSellMenu(string key)
        {
            try
            {
                IList<FoodKind> tempList = new List<FoodKind>();
                //return null if listFoodKind is null or empty
                if (Session.listFoodKindSellMenu == null || Session.listFoodKindSellMenu.Count == 0)
                {
                    return tempList;
                }

                //Filter
                foreach (FoodKind fk in Session.listFoodKindSellMenu)
                {
                    FoodKind tempFk = new FoodKind { foodKindId = fk.foodKindId, foodKindName = fk.foodKindName, foodList = new List<Food>() };
                    foreach (Food f in fk.foodList)
                    {
                        //If food name contains key --> add it to tempFk
                        if (ExtensionString.Change_AV(f.foodName.Trim()).ToLower().Contains(ExtensionString.Change_AV(key).ToLower()))
                        {
                            tempFk.foodList.Add(f);
                        }
                    }
                    //Add food kind to list if food kind 's foods exists.
                    if (tempFk.foodList.Count > 0)
                    {
                        tempList.Add(tempFk);
                    }
                }

                return tempList;
            }
            catch(Exception ex)
            {
                throw new Exception("filterFoodSellMenu happened error : "+ ex.Message);
            }
        }
    }
}
